﻿
//全局变量
page =null;
InitailTime = "";
TableResult_DbList = null;


//分页对象。
function Paging() {
    this.config =
       {
           DivId: "mypaging",
           DivStyle: "",
           MaxNumber: 0
       }

    this.property = {
        indexNumber: 1,
        startNumber: 1,
        endNumber: 10,
    }

    paging_event(this);
    //动作
    if (typeof (Paging.initailed) == "undefined") {
        Paging.prototype.reDraw = function () {
            var htm = '<span  class="BackPage"> <a href="#" style="">&lt;上一页</a></span>\
                <span class="PageNumber"><a class="on " href="#">1</a>\
                <a class="" href="#">10</a></span>\
                <span class="NextPage"><a href="#" >下一页&gt;</a></span>';
            //分页对象
            var pagingObj = $("#" + this.config.DivId)
            //初步绘制出
            pagingObj.html("").html(htm);
            //上一页  页码  下一页 obj
            var pagingBackPage = pagingObj.find(".BackPage");
            var pagingNextPaga = pagingObj.find(".NextPage");
            var pagingNumber = pagingObj.find(".PageNumber");
            //对上一页下一页的绘制
            if (this.config.MaxNumber == this.property.indexNumber) {
                pagingNextPaga.hide();
            }
            if (this.property.indexNumber == 1) {
                pagingBackPage.hide();
            }
            
            //对数码的绘制
            pagingNumber.html("");
            for (var i = this.property.startNumber; i <= this.property.endNumber; i++) {
                if (i > this.config.MaxNumber) {
                    continue;
                }
                var htm_code = '<a class="" href="#">' + i + '</a>';
                if (i == this.property.indexNumber) {
                    htm_code = '<a class="on" href="#">' + i + '</a>';
                }
                pagingNumber.append(htm_code);
            }
        }

    }
    Paging.initailed = true;
}

//分页点击事件
function paging_event(page) {
    $("#" + page.config.DivId).click(function (e) {
        var e = e || window.event,
            target = e.target || e.srcElement;
        //输出点击div的id   
        var indexObj = $(target); //当前点击对象
        //过滤
        if (indexObj[0].tagName != "A")
        { return false; }
        if (parseInt(indexObj.html()) == page.property.indexNumber) { return false; }
        var indexOn = $(this).find(".on");
        if (indexObj.html() == "&lt;上一页") {
            page.property.indexNumber--;
        }

        else if (indexObj.html() == "下一页&gt;") {
            page.property.indexNumber++;
        }
        else {
            page.property.indexNumber = parseInt(indexObj.html());
        }

        var NumberCount = (page.property.endNumber + 1 - page.property.startNumber);
        var Numberdown = page.property.startNumber + 3;
        var NumberUp = page.property.endNumber - 3;


        if (Numberdown > page.property.indexNumber) {
            page.property.startNumber = page.property.startNumber - (Numberdown - page.property.indexNumber);
            page.property.endNumber = page.property.endNumber - (Numberdown - page.property.indexNumber);
            if (page.property.startNumber < 1) {
                page.property.startNumber = 1;
                page.property.endNumber = NumberCount;
            }
        }
        if (page.property.indexNumber > NumberUp) {
            page.property.startNumber = page.property.startNumber + (page.property.indexNumber - NumberUp);
            page.property.endNumber = page.property.endNumber + (page.property.indexNumber - NumberUp);
            if (page.property.endNumber > page.config.MaxNumber) {
                page.property.startNumber = page.config.MaxNumber - NumberCount + 1;
                page.property.endNumber = page.config.MaxNumber;
            }
        }
        PagingClickAfter();
        page.reDraw();
    })
}

//数据初始化
function Initailing()
{
    //s全局数据初始化
    page = new Paging();
    InitailTime = new Date(new Date().getTime() + 8 * 60 * 60 * 1000);//$("#serverTime").val(); //new Date().toLocaleTimeString(); alert(InitailTime);
    TableResult_DbList = [];

    //加载后台数据并初始化数据列表和分页
    param = {
        "TableName": "DMP_Bolg_Shuoshuo",
        "DataTime": InitailTime,
        "IndexDelIds": TableResult_DbList,
        "DateType":0,
        "IsRTData": true,
        "sortName": "PointNumber",
        "sortType": "desc",
        "Filter": {},
        "pagingCount": 10,
        "pagingNumber": 1
    }
    debugger;
    $.post("/JsonDate/getmyTableByTableInfo", { "Tinfo_json": JSON.stringify(param) }, function (mytable, status) {

        if (status == "success") {
            var ssList = mytable.TableResult_DbList;
            var maxPage = Math.ceil(mytable.TableResult_Count / 10);
            //全局数据初始化
            TableResult_DbList = mytable.TableInfo.IndexDelIds;
            //加载数据绘制
            $(".bg_page_top_content_itemList").html("");
            for (var i in ssList) {
                item = ssList[i];
                
                var MessageProfile = "";
                try{
                    MessageProfile = item.MessageProfile.substr(0, 150) + "...";
                } catch (e)
                {
                    MessageProfile = item.MessageProfile;
                }
                var Name = "";
                try {
                    Name = item.Name.substr(0, 40) + "...";
                } catch (e) {
                    Name = item.Name;
                }
               
                var ssContent = '<div class="bg_page_top_content_item">\
                            <div class="bg_page_top_content_item">\
                            <div style="width: 100%; height: 15px;"></div>\
                            <div class="bg_page_top_content_item_info" style="text-align: left;\
                            margin: 0 auto; width: 95%; min-height: 50px; max-height: 500px; ">';

                ssContent += '<dl class="search-list J_search"><dt style="margin-bottom: 10px;"><a class="_index_Detail_jump" data="' + item.id + '" href="' + item.MessagesAddress + '" target="_blank" strategy="search_bc_4_1" style="color: #2981a9; font-size: larger; font-weight: 600;">' + Name + '</a></dt><dd class="search-detail" style="font-size: 14px; color: #666666;margin-bottom: 5px; font-family: microsoft yahei; line-height: 22px; overflow: hidden; text-indent: 2em;">' +MessageProfile + '</dd><dd class="search-link" style=""><a class="_index_Detail_jump" data="' + item.id + '" href="' + item.MessagesAddress + '" target="_blank" strategy="search_bc_4_1" style="color: #5f980b;">' + item.MessagesAddress + '</a></dd></dl>'
                ssContent += '<div style="margin-right: 5%; text-align: right;">\
                                <span class="_index_PageView"  style="color: crimson;margin-right: 69%;">浏览<font>' + item.PageViewNumber + '</font>次</span>\
                                <span class="_index_Point" data="' + item.id + '" style="margin: 5px;">点赞(<font>' + item.PointNumber + '</font>)</span>\
                                <span class="_index_share" data="' + item.id + '" style="margin: 5px;">分享(<font>' + item.shareNumber + '</font>)</span>\
                            </div>\
                        </div>\
                        <div style="width: 100%; height: 15px;"></div>\
                    </div>';
                $(".bg_page_top_content_itemList").append(ssContent);
            }
            //加载页面绘制
            page.config =
        {
            DivId: "mypaging",
            DivStyle: "",
            MaxNumber: maxPage
        }
            page.property = {
                indexNumber: 1,
                startNumber: 1,
                endNumber: 10 < maxPage ? 10 : maxPage,
            }
            page.reDraw();
        }
    });

    Lps();
}
//点击后 数据加载前
function PagingClickAfter() {
    param = {
        "TableName": "DMP_Bolg_Shuoshuo",
        "DataTime": InitailTime,
        "IndexDelIds": TableResult_DbList,
        "IsRTData": false,
        "sortName": "PointNumber",
        "sortType": "desc",
        "Filter": {},
        "pagingCount": 10,
        "pagingNumber": page.property.indexNumber
    }
    $.post("/JsonDate/getmyTableByTableInfo", { "Tinfo_json": JSON.stringify(param) }, function (mytable, status) {
        if (status == "success") {
            var ssList = mytable.TableResult_DbList;
            //加载数据绘制
            $(".bg_page_top_content_itemList").html("");
            for (var i in ssList) {
                item = ssList[i];
                var MessageProfile = "";
                try {
                    MessageProfile = item.MessageProfile.substr(0, 150) + "...";
                } catch (e) {
                    MessageProfile = item.MessageProfile;
                }
                var ssContent = '<div class="bg_page_top_content_item">\
                            <div class="bg_page_top_content_item">\
                            <div style="width: 100%; height: 15px;"></div>\
                            <div class="bg_page_top_content_item_info" style="text-align: left;\
                            margin: 0 auto; width: 95%; min-height: 50px; max-height: 500px; ">';

                ssContent += '<dl class="search-list J_search"><dt style="margin-bottom: 10px;"><a class="_index_Detail_jump" data="' + item.id + '" href="' + item.MessagesAddress + '" target="_blank" strategy="search_bc_4_1" style="color: #2981a9; font-size: larger; font-weight: 600;">' + item.Name + '</a></dt><dd class="search-detail" style="font-size: 14px; color: #666666;margin-bottom: 5px; font-family: microsoft yahei; line-height: 22px; overflow: hidden; text-indent: 2em;">' + MessageProfile + '</dd><dd class="search-link" style=""><a class="_index_Detail_jump" data="' + item.id + '" href="' + item.MessagesAddress + '" target="_blank" strategy="search_bc_4_1" style="color: #5f980b;">' + item.MessagesAddress + '</a></dd></dl>'
                ssContent += '<div style="margin-right: 5%; text-align: right;">\
                                <span class="_index_PageView"  style="color: crimson;margin-right: 69%;">浏览<font>' + item.PageViewNumber + '</font>次</span>\
                                <span class="_index_Point" data="' + item.id + '" style="margin: 5px;">点赞(<font>' + item.PointNumber + '</font>)</span>\
                                <span class="_index_share" data="' + item.id + '" style="margin: 5px;">分享(<font>' + item.shareNumber + '</font>)</span>\
                            </div>\
                        </div>\
                        <div style="width: 100%; height: 15px;"></div>\
                    </div>';
                $(".bg_page_top_content_itemList").append(ssContent);
            }
            background();
        }
    });




}

//初始化后对页面中的浏览 点赞 分享等添加动作
function Lps()
{
    //class="_index_PageView" 
    //class="_index_Point" 
    //class="_index_share" 

    //浏览-主页面监控动作
    $(document).delegate("._index_Detail_jump", "click", function () {
        debugger;
        $.post("/JsonDate/updateSSPSV", { "Type": 'PageViewNumber', "ssid": $(this).attr("data") }, function (mytable, status) {
            if (status == "success") {
              
            }
        });
        var dataobj = $(this).parents(".bg_page_top_content_item").find("._index_PageView").find("font");
        dataobj.html(parseInt(dataobj.html())+1);
    })
    

    //点赞-主页面监控动作
    $(document).delegate("._index_Point", "click", function () {
        debugger;
        $.post("/JsonDate/updateSSPSV", { "Type":'PointNumber', "ssid":$(this).attr("data") }, function (mytable, status) {
            if (status == "success") {
                
            }
        });
        var dataobj = $(this).find("font");
        dataobj.html(parseInt(dataobj.html()) + 1);
    })
    //-主页面监控动作
    $(document).delegate("._index_share","click", function () {
        $.post("/JsonDate/updateSSPSV", { "Type":'shareNumber', "ssid":$(this).attr("data") }, function (mytable, status) {
            if (status == "success") {
            }
        });
        var dataobj = $(this).find("font");
        dataobj.html(parseInt(dataobj.html()) + 1);
    });




}

//所有动作执行
Initailing();








